package com.iafme.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.iafme.dto.req.EducationReqDTO;
import com.iafme.dto.req.MemberReqDTO;
import com.iafme.dto.req.WorkReqDTO;
import com.iafme.dto.res.EducationResDTO;
import com.iafme.dto.res.MemberResDTO;
import com.iafme.dto.res.WorkResDTO;
import com.iafme.service.IEducationService;
import com.iafme.service.IMemberService;
import com.iafme.service.IWorkService;
import com.systemframework.constants.Constants;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/4 16:48
 */
@RestController
@RequestMapping(value = "/member")
@AllArgsConstructor
public class MemberController {

    private final IMemberService memberService;

    /**
     * 个人信息
     * @return
     */
    @GetMapping(value = "/info")
    public MemberResDTO memberInfo(){
        return memberService.findById(StpUtil.getLoginIdAsInt());
    }

    @PutMapping(value = "/update")
    public String updateMember(@RequestBody MemberReqDTO memberReqDTO){
        memberService.updateMember(memberReqDTO);
        return Constants.SUCCESS;
    }

    private final IEducationService educationService;

    /**
     * 保存更新教育
     * @param educationReqDTO
     * @return
     */
    @PostMapping(value = "/saveOrUpdateEducation")
    public EducationResDTO saveOrUpdateEducation(@RequestBody EducationReqDTO educationReqDTO){
        return educationService.saveOrUpdateEducation(educationReqDTO);
    }

    @DeleteMapping(value = "/removeEducation/{id}")
    public String removeEducation(@PathVariable Integer id){
        educationService.removeById(id);
        return Constants.SUCESS;
    }

    private final IWorkService workService;

    /**
     * 保存更新工作经历
     * @param workReqDTO
     * @return
     */
    @PostMapping(value = "/saveOrUpdateWork")
    public WorkResDTO saveOrUpdateWork(@RequestBody WorkReqDTO workReqDTO){
        return workService.saveOrUpdateWork(workReqDTO);
    }

    @DeleteMapping(value = "/removeWork/{id}")
    public String removeWork(@PathVariable Integer id){
        workService.removeById(id);
        return Constants.SUCCESS;
    }




}
